home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
MacTech 1 to 12
/
MacTech-vol-1-12.toast
/
Reference
/
the cmsp digests ('94-'97)
/
csmp digest Vol 3 No 095
< prev
next >
Wrap
Text File
|
1995-04-26
|
70KB
|
1,963 lines
C.S.M.P. Digest Tue, 25 Apr 95 Volume 3 : Issue 95
Today's Topics:
Debugging Memory Manager--Caution
DragManager problem [Q]
How to launch an application with a file?
Offscreenage-Animation-Concepts?
Time Manager Puzzle
Unsigned Integers?
[Q] Byte Reversal
[Q] Getting a list of vRefNums
__MAC__?
The Comp.Sys.Mac.Programmer Digest is moderated by Francois Pottier
(pottier@clipper.ens.fr).
The digest is a collection of article threads from the internet newsgroup
comp.sys.mac.programmer. It is designed for people who read c.s.m.p. semi-
regularly and want an archive of the discussions. If you don't know what a
newsgroup is, you probably don't have access to it. Ask your systems
administrator(s) for details. If you don't have access to news, you may
still be able to post messages to the group by using a mail server like
anon.penet.fi (mail help@anon.penet.fi for more information).
Each issue of the digest contains one or more sets of articles (called
threads), with each set corresponding to a 'discussion' of a particular
subject. The articles are not edited; all articles included in this digest
are in their original posted form (as received by our news server at
nef.ens.fr). Article threads are not added to the digest until the last
article added to the thread is at least two weeks old (this is to ensure that
the thread is dead before adding it to the digest). Article threads that
consist of only one message are generally not included in the digest.
The digest is officially distributed by two means, by email and ftp.
If you want to receive the digest by mail, send email to listserv@ens.fr
with no subject and one of the following commands as body:
help Sends you a summary of commands
subscribe csmp-digest Your Name Adds you to the mailing list
signoff csmp-digest Removes you from the list
Once you have subscribed, you will automatically receive each new
issue as it is created.
The official ftp info is //ftp.dartmouth.edu/pub/csmp-digest.
Questions related to the ftp site should be directed to
scott.silver@dartmouth.edu.
-------------------------------------------------------
>From jwbaxter@olympus.net (John W. Baxter)
Subject: Debugging Memory Manager--Caution
Date: Thu, 30 Mar 1995 00:13:04 -0800
Organization: Internet for the Olympic Peninsula
The Debugging Memory Manager arrived on the April Developer CD. It does
what it says it does, but is not trouble-free on my 8100/80 running System
7.5.1:
WIth the extra checking turned off:
Finder is gigged twice during startup for bad pointers.
The blocks containing bits behind menus (including popups) appear to have
the disposed memory pattern written into them before the area behind the
menus is restored. The result is actually rather colorful.
Lots more bad pointers/handles/exceptions caught if checking is actually
turned on...the secret to operating a menu is to use one hand on the
mouse, and the other to command-G one's way through MacsBug. Eventually,
you get to the Debugging Memory Manager control panel.
I've done some conflict-searching, but seemingly not enough. Apple Menu
Options is an obvious suspect: not guilty. Leonard R's OSA Menu is also
a likely suspect: not guilty. Several others are clean, too.
Fortunately, the removal button in the installer seems to remove successfully.
Don't install this thing just before the big show-and-tell for the boss!
Anyone else having problems?
--John
--
John Baxter Port Ludlow, WA, USA [West shore, Puget Sound]
Isn't C fun?
jwbaxter@pt.olympus.net
+++++++++++++++++++++++++++
>From jwbaxter@olympus.net (John W. Baxter)
Date: Thu, 30 Mar 1995 00:32:41 -0800
Organization: Internet for the Olympic Peninsula
In article <jwbaxter-3003950013040001@ptpm013.olympus.net>,
jwbaxter@olympus.net (John W. Baxter) wrote:
> The Debugging Memory Manager arrived on the April Developer CD. It does
> what it says it does, but is not trouble-free on my 8100/80 running System
> 7.5.1:
>
Tale of woe omitted
The guilty party appears to be the most obvious suspect of all ("the
butler did it"): RamDoubler (1.5.1).
With that disabled and lots of checking turned on, I did see a -104
"unexpected quit" from SimpleText, after I quit SimpleText. Nothing else.
--John (sorry about the self-reply)
--
John Baxter Port Ludlow, WA, USA [West shore, Puget Sound]
Isn't C fun?
jwbaxter@pt.olympus.net
+++++++++++++++++++++++++++
>From ejw@pacersoft.com (Erik James Walter)
Date: Mon, 03 Apr 1995 15:33:45 -0400
Organization: Pacer Software, Inc.
In article <jwbaxter-3003950013040001@ptpm013.olympus.net>,
jwbaxter@olympus.net (John W. Baxter) wrote:
> The Debugging Memory Manager arrived on the April Developer CD. It does
> what it says it does, but is not trouble-free on my 8100/80 running System
> 7.5.1:
>
> WIth the extra checking turned off:
>
> Finder is gigged twice during startup for bad pointers.
>
> The blocks containing bits behind menus (including popups) appear to have
> the disposed memory pattern written into them before the area behind the
> menus is restored. The result is actually rather colorful.
>
> Lots more bad pointers/handles/exceptions caught if checking is actually
> turned on...the secret to operating a menu is to use one hand on the
> mouse, and the other to command-G one's way through MacsBug. Eventually,
> you get to the Debugging Memory Manager control panel.
>
> I've done some conflict-searching, but seemingly not enough. Apple Menu
> Options is an obvious suspect: not guilty. Leonard R's OSA Menu is also
> a likely suspect: not guilty. Several others are clean, too.
>
> Fortunately, the removal button in the installer seems to remove successfully.
>
> Don't install this thing just before the big show-and-tell for the boss!
>
> Anyone else having problems?
>
I am having similiar problems, but I don't have RamDoubler installed.
This is on a 7.1.2 system. I get the annoying (but colorful) menus and
have to spend my time doing the cmd-G switching (I've found that turning
off debugger breaks also helps).
I'm going to do some binary searching of the init's and report back
Erik
+-------------------------------------------+-----------------------+
| [.signature pending FDA approval] | Erik James Walter |
| | Mac Engineer |
| | Pacer Software, Inc. |
+-------------------------------------------+-----------------------+
+++++++++++++++++++++++++++
>From William Knott <knott@apple.com>
Date: Tue, 4 Apr 1995 18:33:10 GMT
Organization: Apple Computer
In article <jwbaxter-3003950013040001@ptpm013.olympus.net> John W.
Baxter, jwbaxter@olympus.net writes:
>The Debugging Memory Manager arrived on the April Developer CD. It does
>what it says it does, but is not trouble-free on my 8100/80 running System
>7.5.1:
>
Version 1.0.1 of the Debugging Memory Manager is incompatable with Virtual
Memory. Turning off VM should solve most of your problems. Version
1.0.2 of DMMM has resolved this problem. Version 1.0.2 will be
distributed
on the May 1995 developer CD.
Any additional problems, please send eMail to :
DMMM@Powertalk.apple.com
Thanks and sorry for any inconveniences
-Bill
+++++++++++++++++++++++++++
>From jwbaxter@olympus.net (John W. Baxter)
Date: Fri, 07 Apr 1995 07:18:52 -0700
Organization: Internet for the Olympic Peninsula
In article <ejw-0304951533450001@ejwmac.pacersoft.com>, ejw@pacersoft.com
(Erik James Walter) wrote:
> In article <jwbaxter-3003950013040001@ptpm013.olympus.net>,
> jwbaxter@olympus.net (John W. Baxter) wrote:
>
> > The Debugging Memory Manager arrived on the April Developer CD. It does
> > what it says it does, but is not trouble-free on my 8100/80 running System
> > 7.5.1:
> >
> > WIth the extra checking turned off:
> >
> > Finder is gigged twice during startup for bad pointers.
> > [etc from JWB]
>
> I am having similiar problems, but I don't have RamDoubler installed.
> This is on a 7.1.2 system. I get the annoying (but colorful) menus and
> have to spend my time doing the cmd-G switching (I've found that turning
> off debugger breaks also helps).
>
> I'm going to do some binary searching of the init's and report back
The problem lies with Debugging Modern Memory Manager version 1.0.1, which
does not work with Virtual Memory (or RamDoubler). Soon there should be a
version 1.0.2 available, which does work with VM (I haven't tried it with
RamDoubler...switching to VM has ended some other problems on my
machine). However, you probably don't WANT to use it with virtual memory
(at least if you have it set to write patterns into free blocks). Unless
your Mac is too fast and you need to relax.
--John
--
John Baxter Port Ludlow, WA, USA [West shore, Puget Sound]
Isn't C fun?
jwbaxter@pt.olympus.net
+++++++++++++++++++++++++++
>From jhiggins@mathworks.com (John Higgins)
Date: Sun, 09 Apr 1995 18:44:11 -0400
Organization: The MathWorks, Inc.
In article <1995Apr4.183310.28450@gallant.apple.com>, William Knott
<knott@apple.com> wrote:
>
> Any additional problems, please send eMail to :
>
> DMMM@Powertalk.apple.com
>
> Thanks and sorry for any inconveniences
>
> -Bill
The README says to "continue" when PC Exchange causes an error at boot
time. I am running Jasik's Debugger, and I cannot seem to get past this
error. My machine (8100/110, System 7.5.1) hangs.
======================
John Higgins
jhiggins@mathworks.com
The MathWorks, Inc.
508-653-1415
---------------------------
>From dat93rli@ludat.lth.se (Rune Lindman)
Subject: DragManager problem [Q]
Date: 29 Mar 1995 14:59:19 GMT
Organization: Lund Institute of Technology, Sweden
I have a problem with the DragManager in my application.
I use a HFSFlavor along with my own type when creating a
drag event. Everything works fine (dragging between my own
documents, dragging to applications installed in Malph and
dragging to directories/discs in the finder).
What I cant get to work is draggin to application icons in
the Finder, the icon highlights but the drag is refused.
Has anyone got this to works?
Please help, Im completely stuck...
/ Rune Lindman
--
S-mail: Rune Lindman | E-mail: dat93rli@ludat.lth.se | Computer Science
Slojdgatan 11 | lindman@df.lth.se | Lund University
227 36 Lund | Fidonet: 2:200/433.2 |------------------
Sweden | Tel/Fax: +46-46-137045 | 2B|^2B
+++++++++++++++++++++++++++
>From jens_alfke@powertalk.apple.com (Jens Alfke)
Date: Wed, 5 Apr 1995 16:04:37 GMT
Organization: Apple Computer, Inc.
In article <3lh82m$he7@symiserver.symantec.com>, Mark Romano
<mromano@bedford.symantec.com> wrote:
> I see the same thing (with HFSFlavor and PromiseHFSFlavor).
> It is apparently a bug in the Finder! (7.1, 7.5, 7.5.1)
No it isn't, I've written code that drags to the Finder, and there's a
sample app that comes with the Drag Manager that demonstrates it too. You
do have to dot all the i's and cross all the t's to get the
PromiseHFSFlavor to work.
Jens Alfke_________OpenDoc Geometer_________jens_alfke@powertalk.apple.com
OpenDoc info: FTP to CILabs.org
Visit Scenic Flood Control Dam No. 3.
+++++++++++++++++++++++++++
>From lindman@df.lth.se (Rune Lindman)
Date: Sun, 9 Apr 1995 09:35:23 GMT
Organization: Lund University Computing Center
In article <jens_alfke-0504951704370001@jensothermac.apple.com>,
jens_alfke@powertalk.apple.com (Jens Alfke) wrote:
>In article <3lh82m$he7@symiserver.symantec.com>, Mark Romano
><mromano@bedford.symantec.com> wrote:
>
>> I see the same thing (with HFSFlavor and PromiseHFSFlavor).
>> It is apparently a bug in the Finder! (7.1, 7.5, 7.5.1)
>
>No it isn't, I've written code that drags to the Finder, and there's a
>sample app that comes with the Drag Manager that demonstrates it too. You
>do have to dot all the i's and cross all the t's to get the
>PromiseHFSFlavor to work.
>
>
>Jens Alfke_________OpenDoc Geometer_________jens_alfke@powertalk.apple.com
> OpenDoc info: FTP to CILabs.org
>
> Visit Scenic Flood Control Dam No. 3.
I am the original poster.
I don't think we are talking about the same thing here.
As I wrote earlier dragging to the Finder works fine.
But creating an HFSFlavor for a document file in my program
and then dragging that *onto an application icon* in the Finder
does not work. The icon gets highlighted but the drag is
refused. I haven't seen any program that does this, not even
Greg's Browser. Is this supposed to work (am I doing something
wrong here)?. However it works just fine to drag to an application
installed in Malph.
I would really appreciate some info on this one since I'm going
to release the application soon.
Regards Rune Lindman.
--
S-mail: Rune Lindman | E-mail: dat93rli@ludat.lth.se | Computer Science
Slojdgatan 11 | lindman@df.lth.se | Lund University
227 36 Lund | Fidonet: 2:200/433.2 |------------------
Sweden | Tel/Fax: +46-46-137045 | 2B|^2B
+++++++++++++++++++++++++++
>From greg@math.harvard.edu (Gregory D. Landweber)
Date: Sun, 09 Apr 1995 11:18:01 -0400
Organization: Harvard University
In article <lindman-0904951135160001@llv95mla.student.lu.se>,
lindman@df.lth.se (Rune Lindman) wrote:
> But creating an HFSFlavor for a document file in my program
> and then dragging that *onto an application icon* in the Finder
> does not work. The icon gets highlighted but the drag is
> refused. I haven't seen any program that does this, not even
> Greg's Browser. Is this supposed to work (am I doing something
> wrong here)?. However it works just fine to drag to an application
> installed in Malph.
The System 7.5 Find File app can do this, and the next version of
Greg's Browser (due out in about a week) will do this as well.
Yes, this is a bug in the Finder, but it is easy to get around. Although
the Finder will highlight applications when you drag over them, it returns
a userCancelledError when you drop. However, it does set the drop location
correctly. So, if you receive a userCancelledError, call GetDropLocation()
to see if the drop location has been set. If it has, launch the application
yourself and send it an ODOC AppleEvent for the dropped files.
-- Greg Landweber
greg@math.harvard.edu
(author of "Greg's Buttons" and "Greg's Browser")
---------------------------
>From aa576@FreeNet.Carleton.CA (Robert Hilchie)
Subject: How to launch an application with a file?
Date: Fri, 7 Apr 1995 15:46:58 GMT
Organization: The National Capital FreeNet
First, let me thank Leonard Rosenthol for sending me the example code for
launching a file using finder events. It works like a charm. By the way,
where are these finder events documented?
Anyway, my question is this: how do I launch an application so that on
startup it opens a particular file, given file specs for the application
and file? I tried to do it by placing a kAEOpenDocuments apple event in the
launchAppParameters field of the LaunchParamBlockRec of LaunchApplication(),
without much success. Perhaps I'm not forming the apple event correctly.
What target ID do I specify, since the application which receives the event
is not running yet? And where do I copy the message buffer from? From the
apple event's dataHandle? Is this the correct approach? Does anyone out there
have some example code to do this? Thanks,
Rob Hilchie
aa576@FreeNet.Carleton.CA
+++++++++++++++++++++++++++
>From skevill@tartarus.uwa.edu.au (Scott Kevill)
Date: 8 Apr 1995 04:05:01 GMT
Organization: The University of Western Australia
Robert Hilchie (aa576@FreeNet.Carleton.CA) wrote:
: First, let me thank Leonard Rosenthol for sending me the example code for
: launching a file using finder events. It works like a charm. By the way,
: where are these finder events documented?
: Anyway, my question is this: how do I launch an application so that on
: startup it opens a particular file, given file specs for the application
: and file? I tried to do it by placing a kAEOpenDocuments apple event in the
: launchAppParameters field of the LaunchParamBlockRec of LaunchApplication(),
: without much success. Perhaps I'm not forming the apple event correctly.
: What target ID do I specify, since the application which receives the event
: is not running yet? And where do I copy the message buffer from? From the
: apple event's dataHandle? Is this the correct approach? Does anyone out there
: have some example code to do this? Thanks,
: Rob Hilchie
: aa576@FreeNet.Carleton.CA
It sounds like you mustn't be forming the apple event correctly.
Here is a function that should do what you want, not sure where I got
it from.
Hope this helps.
Scott Kevill
skevill@tartarus.uwa.edu.au
- -----
OSErr LaunchApplicationWithDocument(const FSSpec * applicationFSSpecPtr,
const FSSpec * documentFSSpecPtr)
{
OSErr retCode;
LaunchParamBlockRec launchParams;
ProcessSerialNumber myPSN;
AppleEvent theAppleEvent;
AEDesc myAddrDesc, launchParamDesc, docDesc;
AEDescList docDescList;
AliasHandle docAlias;
// to simplify cleanup, ensure that handles are nil to start
theAppleEvent.dataHandle = nil;
launchParamDesc.dataHandle = nil;
docDescList.dataHandle = nil;
docDesc.dataHandle = nil;
docAlias = nil;
// the Apple event will need a valid address descriptor (even
// though its contents will not matter since we will not be
// calling AESend) so make one using my own serial number
(void) GetCurrentProcess(&myPSN);
retCode = AECreateDesc(typeProcessSerialNumber, (Ptr) &myPSN,
sizeof(ProcessSerialNumber), &myAddrDesc);
if (retCode != noErr) goto Bail;
// make a descriptor list containing just a descriptor with an
// alias to the document
retCode = AECreateList(nil, 0, false, &docDescList);
if (retCode != noErr) goto Bail;
retCode = NewAlias(nil, documentFSSpecPtr, &docAlias);
if (retCode != noErr) goto Bail;
HLock((Handle) docAlias);
retCode = AECreateDesc(typeAlias, (Ptr) *docAlias,
GetHandleSize((Handle) docAlias), &docDesc);
HUnlock((Handle) docAlias);
if (retCode != noErr) goto Bail;
retCode = AEPutDesc(&docDescList, 0, &docDesc);
if (retCode != noErr) goto Bail;
// now make the 'odoc' AppleEvent descriptor and insert the
// document descriptor list as the direct object
retCode = AECreateAppleEvent(kCoreEventClass, kAEOpenDocuments,
&myAddrDesc, kAutoGenerateReturnID, kAnyTransactionID,
&theAppleEvent);
if (retCode != noErr) goto Bail;
retCode = AEPutParamDesc(&theAppleEvent, keyDirectObject,
&docDescList);
if (retCode != noErr) goto Bail;
// this Apple event will not be sent but rather will be used
// as a parameter to the LaunchApplication call, so coerce it
// to the magic type typeAppParamters
retCode = AECoerceDesc(&theAppleEvent, typeAppParameters,
&launchParamDesc);
if (retCode != noErr) goto Bail;
// finally, fill in the launch parameter block, including the
// Apple event, and make the launch call
HLock((Handle) launchParamDesc.dataHandle);
launchParams.launchAppParameters =
(AppParametersPtr) *(launchParamDesc.dataHandle);
launchParams.launchBlockID = extendedBlock;
launchParams.launchEPBLength = extendedBlockLen;
launchParams.launchFileFlags = launchNoFileFlags;
launchParams.launchControlFlags = launchContinue;
launchParams.launchAppSpec = (FSSpecPtr) applicationFSSpecPtr;
retCode = LaunchApplication(&launchParams);
Bail:
// dispose of everything that was allocated
if (theAppleEvent.dataHandle != nil) AEDisposeDesc(&theAppleEvent);
if (launchParamDesc.dataHandle != nil) AEDisposeDesc(&launchParamDesc);
if (docDescList.dataHandle != nil) AEDisposeDesc(&docDescList);
if (docDesc.dataHandle != nil) AEDisposeDesc(&docDesc);
if (launchParamDesc.dataHandle != nil) AEDisposeDesc(&launchParamDesc);
if (docAlias != nil)
DisposeHandle((Handle) docAlias);
return retCode;
}
- ----
---------------------------
>From joec@johnston.jhuapl.edu (JC)
Subject: Offscreenage-Animation-Concepts?
Date: Mon, 27 Mar 1995 13:55:20 +0000
Organization: Johns Hopkins University/Applied Physics Lab
I know this has been asked many times, but once again.......
1. What is the fastest way to animate an object overtop of a background
when each frame is different ?
Is the fastest way to copy all my individual images into one offscreen
PICT resource and just pluck out the one I need next for the animation? If
so how does one isolate and extract only a small portion of the offscreen
PICT resource and only draw that smaller image to the main screen instead
of the entire offscreen (which I assume includes a background). I've
popped Prince of Persia into Resedit but didn't see animation sequences in
a PICT resource. How did they achieve their graphics ?
2. This may be answered by the above response but if not....How does one
update a main screen view which includes a background and animated objects
without redwawing the entire background again only the animated object ?
I've heard of creating a mask but IM is scarce on the subject and the
extensive digging and viewing of code hasn't yielded clues. Is masking the
fastest way ?
3. This is the last question (for now!) I promise! I've heard of creating
my own graphics routines (instead of using QuickDraw???..) to increase the
speed of drawing. What is it about QuickDraw that makes it too slow and
what exactly will need to improve upon?
Many thanks in advance!
+++++++++++++++++++++++++++
>From al@crucible.powertools.com (Al Evans)
Date: 31 Mar 1995 12:51:28 -0600
Organization: Powertools, Austin, Texas
In article <joec-2703951355200001@covingtons-mac.jhuapl.edu>,
JC <joec@johnston.jhuapl.edu> wrote:
>1. What is the fastest way to animate an object overtop of a background
>when each frame is different ?
Opinions are likely to vary on lots of this. All I can say is that
these are mine, and I do this stuff for a living:-)
Probably the best way is to put all your individual images into one
PICT, draw that PICT into an offscreen GWorld when you initialize your
graphics, and copy rectangles from it as needed. I often expand on this
system to include a resource which contains the source rectangles of
all the individual sub-frames in the PICT.
Keep your background in a separate offscreen GWorld -- you'll need pieces
of it to update the on-screen background as the animated images move.
>2. This may be answered by the above response but if not....How does one
>update a main screen view which includes a background and animated objects
>without redwawing the entire background again only the animated object ?
>I've heard of creating a mask but IM is scarce on the subject and the
>extensive digging and viewing of code hasn't yielded clues. Is masking the
>fastest way ?
Personally, I keep a list of rectangles that need to be redrawn, and
redraw only those rectangles on every animation cycle. Also (personally),
I use a separate offscreen GWorld the size of the background for assembly
of the final image to be copied to the screen. Accepting this additional
overhead in time and memory gives me several advantages. 1) Dealing with
multiple "levels" of overlays is as easy as dealing with one; 2) I can
be clever about merging rectangles on my list of dirty Rects, since only
the rectangles on the list need to be guaranteed valid on any animation
cycle; 3) I can do all the dirty work in 8-bit mode without demanding that
the user alter his monitor settings to run my software.
>3. This is the last question (for now!) I promise! I've heard of creating
>my own graphics routines (instead of using QuickDraw???..) to increase the
>speed of drawing. What is it about QuickDraw that makes it too slow and
>what exactly will need to improve upon?
I find that using custom blitters for any or all offscreen-to-offscreen
copies can be a big win. However, I always use CopyBits() for the final
offscreen-to-onscreen copy. My tests indicate that the slight speed increase
I get from using a custom blitter here (~7%) is not worth the additional
hassle required to support multiple overlapping windows, multiple screens,
multiple graphics modes, etc.
--Al Evans--
--
Al Evans | Graphic Elements: A new standard for
________________________|__ high-performance interactive Macintosh graphics.
al@crucible.powertools.com | Available from mac.archive.umich.edu
- -------------------------| /mac/development/libraries/graphicelements2.sit.hqx
+++++++++++++++++++++++++++
>From catambay@aol.com (Bill the Cat)
Date: Mon, 03 Apr 1995 08:21:55 -0800
Organization: Starfleet Academy
In article <3lhivg$qcf@crucible.powertools.com>,
al@crucible.powertools.com (Al Evans) wrote:
-> In article <joec-2703951355200001@covingtons-mac.jhuapl.edu>,
-> JC <joec@johnston.jhuapl.edu> wrote:
->
->
-> >3. This is the last question (for now!) I promise! I've heard of creating
-> >my own graphics routines (instead of using QuickDraw???..) to increase the
-> >speed of drawing. What is it about QuickDraw that makes it too slow and
-> >what exactly will need to improve upon?
->
-> I find that using custom blitters for any or all offscreen-to-offscreen
-> copies can be a big win. However, I always use CopyBits() for the final
-> offscreen-to-onscreen copy. My tests indicate that the slight speed increase
-> I get from using a custom blitter here (~7%) is not worth the additional
-> hassle required to support multiple overlapping windows, multiple screens,
-> multiple graphics modes, etc.
-> --Al Evans--
I'm interested in learning more about this "custom blitters" stuff.
Sounds complicated (multiple this and multiple that), but since I'm always
hearing about it, I have a strong curiosity about it. Can you provide
reading material references?
_____________________________________________________________________
Bill Catambay
Pascal Programmer on Macintosh and Open VMS
/>
// The purpose of software engineering
(//////[O]>=========================================-
\\ is to manage complexity, not to create it.
\>
____________________________________________________________________
+++++++++++++++++++++++++++
>From al@crucible.powertools.com (Al Evans)
Date: 8 Apr 1995 08:06:15 -0500
Organization: Powertools, Austin, Texas
In article <catambay-0304950821550001@129.197.23.15>,
Bill the Cat <catambay@aol.com> wrote:
[quotes me saying I use custom blitters for offscreen-to-offscreen copies]
>I'm interested in learning more about this "custom blitters" stuff.
>Sounds complicated (multiple this and multiple that), but since I'm always
>hearing about it, I have a strong curiosity about it. Can you provide
>reading material references?
I don't really know if there *is* any reading material on custom blitters
for the Mac. The two references I can think of offhand are the Usenet
Mac Programmer's Guide (does this still exist?) and the code in Tony
Myles' SpriteWorld. There are probably others I don't know of.
*I* use custom blitters for two reasons. First, when I *know*
what the environment is -- for example, if it's offscreen-to-offscreen,
8 bits deep, with no clipping or rectangle-clipping only -- I can save
most or all of the setup time CopyBits uses to determine all these
parameters and choose the correct path through its code. Second,
when I have some special kind of copying to do -- for example, if I'm
doing a "transparent" copy where all pixels of palette index 0 are
simply skipped, or if I want to copy over everything except a particular
shade of blue -- I use a custom blitter.
Another good example is the situation where you want to display a
320X200 bitmap in a 640X480 space -- since you *know* that each pixel
is doubled horizontally and vertically, you can play some tricks to
make the doubling happen "automagically" and save a great deal of time
over CopyBits' scaling.
My tests show that custom blitters save significant amounts of time in
these cases, but that for straight copying, particularly offscreen to
onscreen copying, CopyBits is 1) very hard to beat and 2) much more
versatile than anything I want to write.
--Al Evans--
--
Al Evans | Graphic Elements: A new standard for
________________________|__ high-performance interactive Macintosh graphics.
al@crucible.powertools.com | Available from mac.archive.umich.edu
- -------------------------| /mac/development/libraries/graphicelements2.sit.hqx
---------------------------
>From jmunkki@beta.hut.fi (Juri Munkki)
Subject: Time Manager Puzzle
Date: 9 Apr 1995 21:26:49 GMT
Organization: Helsinki University of Technology
Here's a nice little puzzle that I ran into. I use the time manager to measure
time in milliseconds from a certain point in time. Here's the code that I
use to read the time:
long CSoundMixer::ReadTime()
{
long remaining;
long timeBase;
RmvTime((QElemPtr)&timerRec.t);
timeBase = timerRec.timeBase;
remaining = timerRec.t.tmCount;
InsXTime((QElemPtr)&timerRec.t);
PrimeTime((QElemPtr)&timerRec.t, 0);
if(remaining < 0)
remaining /= -1000;
return timeBase + CYCLEMILLISECS - remaining;
}
Now the application that uses this routine happens to be a sound system and
the current time is needed both from a doubleback routine (interrupt level)
and from the application itself.
The challenge is that the interrupt can happen between the RmvTime and
PrimeTime calls and during the period, the current time can not be
read with this method.
Here's how I "solved" this puzzle.
Create two time manager tasks and prime them as close to each other
as possible. Assuming the time manager is reliable, they will measure
the same time. The other task can be used from the interrupt routine
and the other one from other places.
It seems to work quite well, but it is not a very elegant solution,
so I wonder if anyone has suggestions for a better way to do this.
--
Juri Munkki jmunkki@hut.fi There ain't no such thing as a shareware lunch.
http://www.hut.fi/~jmunkki Windsurfing: Faster than the wind.
+++++++++++++++++++++++++++
>From reinder@neuretp.biol.ruu.nl (Reinder Verlinde)
Date: Mon, 10 Apr 1995 08:49:09 GMT
Organization: Rijksuniversiteit Utrecht
In article <3m9jep$mcm@nukkekoti.cs.hut.fi>, jmunkki@beta.hut.fi (Juri
Munkki) wrote:
> Here's a nice little puzzle that I ran into. I use the time manager to measure
> time in milliseconds from a certain point in time. Here's the code that I
> use to read the time:
>
> ...
>
>
> Here's how I "solved" this puzzle.
>
> Create two time manager tasks and prime them as close to each other
> as possible. Assuming the time manager is reliable, they will measure
> the same time. The other task can be used from the interrupt routine
> and the other one from other places.
>
> It seems to work quite well, but it is not a very elegant solution,
> so I wonder if anyone has suggestions for a better way to do this.
>
> --
> Juri Munkki jmunkki@hut.fi There ain't no such thing as a shareware
lunch.
> http://www.hut.fi/~jmunkki Windsurfing: Faster than the wind.
One nice way (as far as the source code goes) I see is to create a single
time manager task which interrupts every millisecond, and updates a global
variable 'gNumMillis'. This will probably slow down your program, though.
A better (probably the only good way) alternative is to disable interrupts
from before 'RmvTime' to after 'PrimeTime', thus implementing a kind of
semaphor around the 'critical section'. Your application won't interrupt
your interrupt, so this half-semaphor will be sufficient.
I don't know (from my head) how to disable interrupts, but source to do
it can be found in the VideoToolbox.
Reinder Verlinde
+++++++++++++++++++++++++++
>From jager@netcom.com (Marcus Jager)
Date: Mon, 10 Apr 1995 17:10:17 GMT
Organization: Mammoth Micro Productions
In article <3m9jep$mcm@nukkekoti.cs.hut.fi>, jmunkki@beta.hut.fi (Juri
Munkki) wrote:
>Here's a nice little puzzle that I ran into. I use the time manager to measure
>time in milliseconds from a certain point in time. Here's the code that I
>use to read the time:
[...code using TimeManager...]
>Now the application that uses this routine happens to be a sound system and
>the current time is needed both from a doubleback routine (interrupt level)
>and from the application itself.
Can you require that Quicktime is available?
If so the you could use a TimeBase. (See NIM QT 2-315)
Create the timer and start it running like this
systemClock = NewTimeBase();
SetTimeBaseValue(systemClock,0,1000);
SetTimeBaseRate(systemClock,1L<<16);
then get the current millisecond time like this, which is interrupt safe
time = GetTimeBaseTime(systemClock,1000,nil);
you can get the time to any resolution like this. (upto the limit of the
default 'clok' component, which claims microsecs accuracy)
Marcus.
___________________________________________________________________
Marcus Jager <jager@netcom.com> Mac Programmer +1-303-237-5776
Mammoth Micro Productions Fax: +1-303-237-6475
---------------------------
>From kurisuto@babel.ling.upenn.edu (Sean Crist)
Subject: Unsigned Integers?
Date: 7 Apr 1995 16:39:42 GMT
Organization: ABBA Fan Club
Arrrgh-- after hacking Macs for five years, I can't believe this is the
first time I've run into this question. I've checked all my reference
books and haven't found the answer, so here's my question.
Is there a kind of Pascal type 'UnsignedInteger' or some such, where the
values are 0 to 65535 rather than -32767 to 32767? (I'm using THINK Pascal,
BTW.)
The reason I want this is that I'm taking two RGB colors and performing
various comparisons and calculations on them (e.g. creating a color table
with a continuum of blended shades in between the two original colors)
Since the values for R,G,B start at 0, I want 40000 > 20000 to be true.
But since Pascal's Integer type treats 40000 as -7232, it works out that
40000 < 20000. (I think I've got this right.)
If I absolutely have to, I can write some very Baroque routines to do these
calculations using ordinary integer-typed variables, but there has to be
some better way.
\/ __ __ _\_ --Sean Crist (kurisuto@unagi.cis.upenn.edu)
--- | | \ / For a free copy of the Bill of Rights, finger
_| ,| ,| ----- this account.
_| ,| ,| [_] Q: What do Standard Oil, AT&T, and Microsoft have in
| | | [_] common? A: Nothing... yet.
+++++++++++++++++++++++++++
>From dstone@alchemy.chem.utoronto.ca (David Stone)
Date: Fri, 7 Apr 1995 19:28:57 GMT
Organization: University of Toronto Chemistry
In article <3m3pse$i1i@netnews.upenn.edu>, kurisuto@babel.ling.upenn.edu
(Sean Crist) wrote:
>
> Arrrgh-- after hacking Macs for five years, I can't believe this is the
> first time I've run into this question. I've checked all my reference
> books and haven't found the answer, so here's my question.
>
> Is there a kind of Pascal type 'UnsignedInteger' or some such, where the
> values are 0 to 65535 rather than -32767 to 32767? (I'm using THINK Pascal,
> BTW.)
>
I don't know about pascal, but in C the RGB colour components are
unsigned short's within the RGBColor data struct
Dave Stone
+++++++++++++++++++++++++++
>From kurisuto@babel.ling.upenn.edu (Sean Crist)
Date: 7 Apr 1995 20:49:38 GMT
Organization: University of Pennsylvania, Linguistics Department
In article <dstone-070495153148@csgmac.chem.utoronto.ca>,
David Stone <dstone@alchemy.chem.utoronto.ca> wrote:
>In article <3m3pse$i1i@netnews.upenn.edu>, kurisuto@babel.ling.upenn.edu
>(Sean Crist) wrote:
>>
>> Arrrgh-- after hacking Macs for five years, I can't believe this is the
>> first time I've run into this question. I've checked all my reference
>> books and haven't found the answer, so here's my question.
>>
>> Is there a kind of Pascal type 'UnsignedInteger' or some such, where the
>> values are 0 to 65535 rather than -32767 to 32767? (I'm using THINK Pascal,
>> BTW.)
>I don't know about pascal, but in C the RGB colour components are
>unsigned short's within the RGBColor data struct
Thanks, but that won't help me; I'm working in Think Pascal and my
application is over 30,000 lines long; it wouldn't be worth it for me to
learn a new language and translate all my code for just this one problem.
:-(
\/ __ __ _\_ --Sean Crist (kurisuto@unagi.cis.upenn.edu)
--- | | \ / For a free copy of the Bill of Rights, finger
_| ,| ,| ----- this account.
_| ,| ,| [_] Q: What do Standard Oil, AT&T, and Microsoft have in
| | | [_] common? A: Nothing... yet.
+++++++++++++++++++++++++++
>From skevill@tartarus.uwa.edu.au (Scott Kevill)
Date: 8 Apr 1995 04:08:32 GMT
Organization: The University of Western Australia
Sean Crist (kurisuto@babel.ling.upenn.edu) wrote:
: Is there a kind of Pascal type 'UnsignedInteger' or some such, where the
: values are 0 to 65535 rather than -32767 to 32767? (I'm using THINK Pascal,
: BTW.)
Just declare a type from 0 to 65535.
TYPE
UnsInt = 0..65535;
Hope this helps.
Scott Kevill
skevill@tartarus.uwa.edu.au
+++++++++++++++++++++++++++
>From Bruce@hoult.actrix.gen.nz (Bruce Hoult)
Date: Sun, 9 Apr 1995 19:50:56 +1200 (NZDT)
Organization: (none)
kurisuto@babel.ling.upenn.edu (Sean Crist) writes:
> Arrrgh-- after hacking Macs for five years, I can't believe this is the
> first time I've run into this question. I've checked all my reference
> books and haven't found the answer, so here's my question.
>
> Is there a kind of Pascal type 'UnsignedInteger' or some such, where the
> values are 0 to 65535 rather than -32767 to 32767? (I'm using THINK Pascal,
> BTW.)
Sorry. No can do :-(
> The reason I want this is that I'm taking two RGB colors and performing
> various comparisons and calculations on them (e.g. creating a color table
> with a continuum of blended shades in between the two original colors)
> Since the values for R,G,B start at 0, I want 40000 > 20000 to be true.
> But since Pascal's Integer type treats 40000 as -7232, it works out that
> 40000 < 20000. (I think I've got this right.)
>
> If I absolutely have to, I can write some very Baroque routines to do these
> calculations using ordinary integer-typed variables, but there has to be
> some better way.
I don't know what anyone else does, but back when I was still using Pascal
I used to do stuff like:
const fudgefactor = -32768;
... and then compare (a + fudgefactor) against (b + fudgefactor).
This gives all the correct orderings for "unsigned" numbers.
-- Bruce
+++++++++++++++++++++++++++
>From jwbaxter@olympus.net (John W. Baxter)
Date: Sat, 08 Apr 1995 21:02:48 -0700
Organization: Internet for the Olympic Peninsula
In article <3m3pse$i1i@netnews.upenn.edu>, kurisuto@babel.ling.upenn.edu
(Sean Crist) wrote:
> Arrrgh-- after hacking Macs for five years, I can't believe this is the
> first time I've run into this question. I've checked all my reference
> books and haven't found the answer, so here's my question.
>
> Is there a kind of Pascal type 'UnsignedInteger' or some such, where the
> values are 0 to 65535 rather than -32767 to 32767? (I'm using THINK Pascal,
> BTW.)
No. [Wirth added an unsigned type to Modula, named CARDINAL.]
> The reason I want this is that I'm taking two RGB colors and performing
> various comparisons and calculations on them (e.g. creating a color table
> with a continuum of blended shades in between the two original colors)
> Since the values for R,G,B start at 0, I want 40000 > 20000 to be true.
> But since Pascal's Integer type treats 40000 as -7232, it works out that
> 40000 < 20000. (I think I've got this right.)
Run some tests...there are more problems in thought experiments than there
are in actual code (because of the actual process of comparing things, and
the nature of the arithmetic the chip[s] we use perform. In many cases,
you'll find that you don't actually have a problem (but I think you've
cited a case where you do. [You routinely compare to Mac times, and the
later one is larger than the earlier one. But both are negative (negative
time began in 1972), so the later one is arithmetically smaller).
> If I absolutely have to, I can write some very Baroque routines to do these
> calculations using ordinary integer-typed variables, but there has to be
> some better way.
"Plant" your INTEGER into the right-hand two bytes of a LONGINT you've
previously zeroed. [-1 is sometimes the right initial state.] [Using the
usual anti-Wirth trickery.] Do your math. Note whether there are bits to
the left of the right two bytes of the result, and adjust. Grab the right
two bytes. That covers most cases, if memory serves. [As long as you
keep your code on a Pascal compiler which *has* the LONGINT extension, and
hardware which does 2's complement binary arithmetic. What I said blows
away portability to other environments, such as whatever machines remain
in service doing signed-magnitude integer arithmetic.]
--John
--
John Baxter Port Ludlow, WA, USA [West shore, Puget Sound]
Isn't C fun?
jwbaxter@pt.olympus.net
+++++++++++++++++++++++++++
>From jwbaxter@olympus.net (John W. Baxter)
Date: Tue, 11 Apr 1995 20:03:24 -0700
Organization: Internet for the Olympic Peninsula
In article <3m5280$mdk@styx.uwa.edu.au>, skevill@tartarus.uwa.edu.au
(Scott Kevill) wrote:
> Sean Crist (kurisuto@babel.ling.upenn.edu) wrote:
> : Is there a kind of Pascal type 'UnsignedInteger' or some such, where the
> : values are 0 to 65535 rather than -32767 to 32767? (I'm using THINK Pascal,
> : BTW.)
>
> Just declare a type from 0 to 65535.
>
> TYPE
> UnsInt = 0..65535;
Well, that can be declared. But it's a subrange of LONGINT, and is four
bytes wide (in the Pascal implementations I'm familiar with. [Just as
0..255 is two bytes wide.]
Standard Pascal doesn't do unsigned, and with the Macintosh Pascals are
extended in various ways (as are all useful Pascals, the one's I've used
aren't extended in the direction of unsigned).
--John
--
John Baxter Port Ludlow, WA, USA [West shore, Puget Sound]
Isn't C fun?
jwbaxter@pt.olympus.net
---------------------------
>From chris-b@cs.auckland.ac.nz (chris-b)
Subject: [Q] Byte Reversal
Date: Tue, 04 Apr 1995 15:55:04 +1200
Organization: HyperMedia Unit, Comp Sci, Auckland University
Hi All,
I'm reading audio data from an audio CD and playing it with Sound Manager
3.0. The CD data however, is little endian. So I need to byte swap pairs
in-place.
I have a handle to a buffer containing the audio data, each four bytes
contains a left and right sample (each 16 bits). The bytes within each
sample need reversing.
Currently my code looks something like this:
- -----------------------------------------------------------------------------
Handle AudioData;
UInt32 i;
UInt32 Frame;
for (i = 0;i < 441000;i++)
{
Frame = ((UInt32*)(*AudioData))[i];
Frame = ((Frame >> 8) & 0x00FF00FF) | ((Frame << 8) & 0xFF00FF00);
((UInt32*)(*AudioData))[i] = Frame;
}
- -----------------------------------------------------------------------------
Does anybody have a better version (in C, for 68K or PPC)? Please post it
and forward me an e-mail copy.
Thanks In Advance,
Chris B
- ---------------------------------------------------------------------
NewZealand:AucklandUniversity:ComputerScience:HyperMediaUnit:ChrisBurns
Internet: chris-b@cs.auckland.ac.nz
Phone: +64 9 373-7599 x6194
Fax: +64 9 373-7453 Async, therefore I am.
- ---------------------------------------------------------------------
+++++++++++++++++++++++++++
>From chris-b@cs.auckland.ac.nz (chris-b)
Date: Tue, 04 Apr 1995 19:17:54 +1200
Organization: HyperMedia Unit, Comp Sci, Auckland University
In article <chris-b-0404951555040001@hmu7.cs.auckland.ac.nz>,
chris-b@cs.auckland.ac.nz wrote:
>So I need to byte swap pairs in-place.
>
>I have a handle to a buffer containing the audio data, each four bytes
>contains a left and right sample (each 16 bits). The bytes within each
>sample need reversing.
The latest version goes something like this:
- -----------------------------------------------------------------------------
UInt32 *FramePtr;
UInt32 *FrameEnd;
UInt32 Frame;
for (FramePtr = (UInt32*)*AudioData,FrameEnd = FramePtr +
441000;FramePtr < FrameEnd;FramePtr++)
{
Frame = *FramePtr;
Frame = ((Frame >> 8) & 0x00FF00FF) | ((Frame << 8) & 0xFF00FF00);
*FramePtr = Frame;
}
- -----------------------------------------------------------------------------
Does anybody have a better version (in C, for 68K or PPC)? Please post it
and forward me an e-mail copy.
Thanks In Advance,
Chris B
- ---------------------------------------------------------------------
NewZealand:AucklandUniversity:ComputerScience:HyperMediaUnit:ChrisBurns
Internet: chris-b@cs.auckland.ac.nz
Phone: +64 9 373-7599 x6194
Fax: +64 9 373-7453 Async, therefore I am.
- ---------------------------------------------------------------------
+++++++++++++++++++++++++++
>From jthill@netcom.com (Jim Hill)
Date: Tue, 4 Apr 1995 16:48:53 GMT
Organization: biological <-- hey, a one-word oxymoron!
On my PPC/5.5, this code is about 30% faster at UNROLL 1, about 40% faster
at UNROLL 2, and about 46% faster at UNROLL 4. If you're doing this more
than a few times, it matters :-)
The CW PPC optimizer doesn't do real well at dealing with constants. Some
other things (maybe doing a little unrolling, especially when you know the
loop will run for a while, until the schedule doesn't improve much) might
be nice, too, but most of it's not hoisting the dang constants.
#define BLKSIZE 441000
void Obswap(UInt32 **AudioData);
void bswap(UInt32 (*AudioData)[BLKSIZE]);
int
main(void)
{
UInt32 (*AudioData)[BLKSIZE] = (void*)NewPtr(sizeof *AudioData);
volatile SInt32 startmine,starthis,endhis,ahis,amine;
volatile float aratio;
int count;
if ( !AudioData )
return 0;
bswap(AudioData);
startmine=LMGetTicks();
for ( count = 60 ; count ; --count )
bswap(AudioData);
starthis=LMGetTicks();
for ( count = 60 ; count ; --count )
Obswap((UInt32**)&AudioData);
endhis=LMGetTicks();
aratio = (float)(ahis=endhis-starthis) / (amine=starthis-startmine);
DisposePtr((Ptr)AudioData);
return 0;
}
void bswap(UInt32 (*AudioData)[BLKSIZE])
{
register UInt32 *pf = *AudioData;
register UInt32 f0,f1,f2,f3;
register UInt32 m = 0x00ff00ff;
#define UNROLL 2
{ long n = BLKSIZE/UNROLL;
do {
f0 = pf[0];
#if UNROLL > 1
f1 = pf[1];
#endif
#if UNROLL > 2
f2 = pf[2];
f3 = pf[3];
#endif
pf[0] = ((f0&m)<<8) | ((f0>>8)&m);
#if UNROLL > 1
pf[1] = ((f1&m)<<8) | ((f1>>8)&m);
#endif
#if UNROLL > 2
pf[2] = ((f2&m)<<8) | ((f2>>8)&m);
pf[3] = ((f3&m)<<8) | ((f3>>8)&m);
#endif
pf += UNROLL;
} while ( --n ); }
}
void Obswap(UInt32 **AudioData)
{
UInt32 *FramePtr;
UInt32 *FrameEnd;
UInt32 Frame;
for (FramePtr = (UInt32*)*AudioData,FrameEnd = FramePtr +
441000;FramePtr < FrameEnd;FramePtr++)
{
Frame = *FramePtr;
Frame = ((Frame >> 8) & 0x00FF00FF) | ((Frame << 8) & 0xFF00FF00);
*FramePtr = Frame;
}
}
--
Jim Hill
jthill@netcom.com PGPrint 6B 85 76 D1 EF BA 2C 78 12 25 8A 5A BF F3 37 7E
+++++++++++++++++++++++++++
>From Turlough_O'Connor@qmgate.corp.apple.com (Turlough O'Connor)
Date: Wed, 05 Apr 1995 18:58:06 +0100
Organization: Contractor, Apple Computer Ltd, Cork, Ireland
In article <chris-b-0404951555040001@hmu7.cs.auckland.ac.nz>,
chris-b@cs.auckland.ac.nz wrote:
>
> I have a handle to a buffer containing the audio data, each four bytes
> contains a left and right sample (each 16 bits). The bytes within each
> sample need reversing.
>
> Currently my code looks something like this:
>
>
- -----------------------------------------------------------------------------
>
> Handle AudioData;
> UInt32 i;
> UInt32 Frame;
>
> for (i = 0;i < 441000;i++)
> {
> Frame = ((UInt32*)(*AudioData))[i];
> Frame = ((Frame >> 8) & 0x00FF00FF) | ((Frame << 8) & 0xFF00FF00);
> ((UInt32*)(*AudioData))[i] = Frame;
> }
>
>
- -----------------------------------------------------------------------------
>
> Does anybody have a better version (in C, for 68K or PPC)? Please post it
> and forward me an e-mail copy.
Well, for a start, dereference the 'AudioData' handle outside of the loop,
e.g.,
register UInt32 *audioDataPtr = (UInt32 *)*AudioData;
And use 'audioDataPtr' inside your loop.
Note! This will work only as long as your loop doesn't move memory, in
which case you should lock/unlock your handle appropriately.
A further optimisation can be made on the 68K:
#pragma parameter __D0 ByteSwapLong(__D0)
unsigned long ByteSwapLong(unsigned long val) THREEWORDINLINE(
0xe058, // ror.w #8, d0
0x4840, // swap d0
0xe058); // ror.w #8, d0
You should thus be able to say something like
UInt32 *audioDataPtr = (UInt32 *)*AudioData;
for (i = 0; i < 441000; ++i)
audioDataPtr[i] = ByteSwapLong(audioDataPtr[i]);
For PPC, the 'rwlinm' instruction may be useful, but unfortunately I've
not got access to the PPC manual at the moment... (and to be honest, my
PPC asm isn't up to much yet!)
Have fun!
--turly
--
Is it *really* just a coincidence that jGNEFilter == 666?
turlough_o'connor@qmgate.corp.apple.com turly@applelink.apple.com
+++++++++++++++++++++++++++
>From des7f@tweety.ipc.virginia.edu. (Dave Sappington)
Date: Thu, 6 Apr 1995 06:44:50 GMT
Organization: Institute for Parallel Computation
In article <chris-b-0404951555040001@hmu7.cs.auckland.ac.nz>
chris-b@cs.auckland.ac.nz (chris-b) writes:
> Handle AudioData;
> UInt32 i;
> UInt32 Frame;
>
> for (i = 0;i < 441000;i++)
> {
> Frame = ((UInt32*)(*AudioData))[i];
> Frame = ((Frame >> 8) & 0x00FF00FF) | ((Frame << 8) & 0xFF00FF00);
> ((UInt32*)(*AudioData))[i] = Frame;
> }
Here's a 68K version of your function (Think C flavor; don't know how
CW handles it). I don't know PPC assembly so I can't help you there.
Dave
==========================
#define N_SAMPLE 441000L
#define UNROLL_FACTOR 2
void SwapAudio ( Handle h )
{
asm {
move.l h,a0 ; deref
move.l (a0),a0 ; handle
move.l #N_SAMPLE/2,d1
move.l d1,d2 ; split counter into two shorts 'cause
swap d2 ; I can't recall the 32-bit dbra form
bra.s @2
@1
move.l (a0),d0 ; grab from memory
ror.w #8,d0 ; swap chars in low short
swap d0 ; swap shorts
ror.w #8,d0 ; swap chars in high short
swap d0 ; swap shorts ( back to original order )
move.l d0,(a0)+ ; put back in memory and auto-increment
move.l (a0),d0 ; gratuitous unrolling of the loop
ror.w #8,d0
swap d0
ror.w #8,d0
swap d0
move.l d0,(a0)+
@2 dbra d1,@1 ; use two 16-bit countdowns 'cause
dbra d2,@1 ; I can't recall the 32-bit dbra form
}
}
Dave Sappington des7f@virginia.edu
Institute for Parallel Computation University of Virginia
+++++++++++++++++++++++++++
>From Turlough_O'Connor@qmgate.corp.apple.com (Turlough O'Connor)
Date: Thu, 06 Apr 1995 12:41:39 +0100
Organization: Contractor, Apple Computer Ltd, Cork, Ireland
In article
<something-my-newsreader-has-forgotten-and-probably-never-posted-anyway-dammit>,
I said:
>In article <chris-b-0404951555040001@hmu7.cs.auckland.ac.nz>,
>chris-b@cs.auckland.ac.nz wrote:
>
>>Handle AudioData;
>>UInt32 i;
>>UInt32 Frame;
>>
>> for (i = 0;i < 441000;i++)
>> {
>> Frame = ((UInt32*)(*AudioData))[i];
>> Frame = ((Frame >> 8) & 0x00FF00FF) | ((Frame << 8) & 0xFF00FF00);
>> ((UInt32*)(*AudioData))[i] = Frame;
>> }
>>
>
>Well, for a start, dereference the 'AudioData' handle outside of the loop,
>e.g.,
>
> register UInt32 *audioDataPtr = (UInt32 *)*AudioData;
>
>And use 'audioDataPtr' inside your loop.
>Note! This will work only as long as your loop doesn't move memory, in
>which case you should lock/unlock your handle appropriately.
>
>A further optimisation can be made on the 68K:
>
>#pragma parameter __D0 ByteSwapLong(__D0)
>unsigned long ByteSwapLong(unsigned long val) THREEWORDINLINE(
> 0xe058, // ror.w #8, d0
> 0x4840, // swap d0
> 0xe058); // ror.w #8, d0
>
>You should thus be able to say something like
>
> UInt32 *audioDataPtr = (UInt32 *)*AudioData;
>
> for (i = 0; i < 441000; ++i)
> audioDataPtr[i] = ByteSwapLong(audioDataPtr[i]);
>
>For PPC, the 'rwlinm' instruction may be useful, but unfortunately I've
>not got access to the PPC manual at the moment... (and to be honest, my
>PPC asm isn't up to much yet!)
>
>Have fun!
WHOOPS! I've just realised that my ByteSwapLong macro will actually
reverse your left and right channels as well! You need an additional
'swap d0' at the end if you just want to swap the bytes in the words:
unsigned long ByteSwapLong(unsigned long val) FOURWORDINLINE(
0xe058, // ror.w #8, d0
0x4840, // swap d0
0xe058, // ror.w #8, d0
0x4840); // swap d0
Some experimentation may be in order; it might be quicker on certain CPUs
to pickup and swap words (shorts) at a time. Possibly.
You could use
unsigned short ByteSwapWord(unsigned short val) ONEWORDINLINE(0xe058);
Alternatively, you might like to try the following 68K asm
(which is off the top of my head, and might therefore be wrong)
;; pascal void ReverseBytesInWordPairs(short *bufPtr, unsigned long nElems)
;;
;; bufPtr points to ARRAY[1..nElems] OF RECORD
;; leftData, rightData : SHORT
;; END;
;; Pardon my Pascal.
REVERSEBYTESINWORDPAIRS PROC EXPORT
move.l (Sp)+, a1 ;; return address
move.l (Sp)+, d1 ;; nElems -- SETS FLAGS
move.l (Sp)+, a0 ;; bufPtr -- **DOESN'T** set flags
beq.s @end ;; Note!! branches if 'd1' == 0.
@1
move.l (a0), d0 ;; pickup left + right channel words
ror.w #8, d0 ;; byteswap right channel
swap d0
ror.w #8, d0 ;; byteswap left channel
swap d0
move.l d0, (a0)+ ;; write out in place
subq.l #1, d1
bne.s @1 ;; counter
@end
jmp a1 ;; finished!
ENDP ;; ReverseBytesInWordPairs
Although a good C compiler should be able to produce code more or less
like this from your original.
Anyway, sorry for any confusion, and
Have Fun!
-turly
--
Is it *really* just a coincidence that jGNEFilter == 666?
turlough_o'connor@qmgate.corp.apple.com turly@applelink.apple.com
+++++++++++++++++++++++++++
>From AppleGG@lamg.com (Gordon Apple)
Date: 06 Apr 1995 22:23:34 GMT
Organization: Los Angeles Macintosh Group BBS
I'm willing to bet that what you have suggested is about as good as
you're going to get, depending on what optimizations the compiler makes. You
could find different ways to write the statement, e.g., avoiding the local
variable, but it wouldn't help the actual computation.
Optimizing the operations depends heavily on what processor is being
used. The local variable "Frame" should be a register and the two masks
should also be stored first in registers. If using a DSP or multi-ALU
processor, the loop overhead and address computation could be zilch. The
throughput in the pipeline could be as little as two or three cycles per loop
pass. Heck, we had a multi-ALU-matrix-switched DSP that would have easily
done that operation (pipelined) in one cycle. Also, if you could work with
64-bit words, you should be able to run twice as fast.
========================================================
========================================================
I'm reading audio data from an audio CD and playing it with Sound Manager
3.0. The CD data however, is little endian. So I need to byte swap pairs
in-place.
I have a handle to a buffer containing the audio data, each four bytes
contains a left and right sample (each 16 bits). The bytes within each
sample need reversing.
Currently my code looks something like this:
- -----------------------------------------------------------------------------
Handle AudioData;
UInt32 i;
UInt32 Frame;
for (i = 0;i < 441000;i++)
{
Frame = ((UInt32*)(*AudioData))[i];
Frame = ((Frame >> 8) & 0x00FF00FF) | ((Frame << 8) & 0xFF00FF00);
((UInt32*)(*AudioData))[i] = Frame;
}
- -----------------------------------------------------------------------------
Does anybody have a better version (in C, for 68K or PPC)? Please post it
and forward me an e-mail copy.
+++++++++++++++++++++++++++
>From AppleGG@lamg.com (Gordon Apple)
Date: 06 Apr 1995 22:23:34 GMT
Organization: Los Angeles Macintosh Group BBS
I'm willing to bet that what you have suggested is about as good as
you're going to get, depending on what optimizations the compiler makes. You
could find different ways to write the statement, e.g., avoiding the local
variable, but it wouldn't help the actual computation.
Optimizing the operations depends heavily on what processor is being
used. The local variable "Frame" should be a register and the two masks
should also be stored first in registers. If using a DSP or multi-ALU
processor, the loop overhead and address computation could be zilch. The
throughput in the pipeline could be as little as two or three cycles per loop
pass. Heck, we had a multi-ALU-matrix-switched DSP that would have easily
done that operation (pipelined) in one cycle. Also, if you could work with
64-bit words, you should be able to run twice as fast.
========================================================
========================================================
I'm reading audio data from an audio CD and playing it with Sound Manager
3.0. The CD data however, is little endian. So I need to byte swap pairs
in-place.
I have a handle to a buffer containing the audio data, each four bytes
contains a left and right sample (each 16 bits). The bytes within each
sample need reversing.
Currently my code looks something like this:
- -----------------------------------------------------------------------------
Handle AudioData;
UInt32 i;
UInt32 Frame;
for (i = 0;i < 441000;i++)
{
Frame = ((UInt32*)(*AudioData))[i];
Frame = ((Frame >> 8) & 0x00FF00FF) | ((Frame << 8) & 0xFF00FF00);
((UInt32*)(*AudioData))[i] = Frame;
}
- -----------------------------------------------------------------------------
Does anybody have a better version (in C, for 68K or PPC)? Please post it
and forward me an e-mail copy.
+++++++++++++++++++++++++++
>From Bruce@hoult.actrix.gen.nz (Bruce Hoult)
Date: Mon, 10 Apr 1995 14:08:39 +1200 (NZDT)
Organization: (none)
des7f@tweety.ipc.virginia.edu. (Dave Sappington) writes:
> void SwapAudio ( Handle h )
> {
> asm {
> move.l h,a0 ; deref
> move.l (a0),a0 ; handle
> move.l #N_SAMPLE/2,d1
> move.l d1,d2 ; split counter into two shorts 'cause
> swap d2 ; I can't recall the 32-bit dbra form
> bra.s @2
> @1
> move.l (a0),d0 ; grab from memory
> ror.w #8,d0 ; swap chars in low short
> swap d0 ; swap shorts
> ror.w #8,d0 ; swap chars in high short
> swap d0 ; swap shorts ( back to original order )
> move.l d0,(a0)+ ; put back in memory and auto-increment
>
> move.l (a0),d0 ; gratuitous unrolling of the loop
> ror.w #8,d0
> swap d0
> ror.w #8,d0
> swap d0
> move.l d0,(a0)+
>
> @2 dbra d1,@1 ; use two 16-bit countdowns 'cause
> dbra d2,@1 ; I can't recall the 32-bit dbra form
> }
> }
There isn't a 32-bit DBRA. What you did is OK, but you can save a register
(which are pretty precious on the 68K) at the cost of two extra instructions
every 65536 loops (i.e. insignificant), with the same code size as you have,
by doing:
move.l #N_SAMPLE/2,d1
bra.s @3
@1 swap d1
@2
; your loop body here
@3 dbra d1,@2
swap d1
dbra d1,@1
-- Bruce
---------------------------
>From Gilles Dignard <gdignard@hookup.net>
Subject: [Q] Getting a list of vRefNums
Date: 7 Apr 1995 14:37:16 GMT
Organization: HookUp Communication Corporation, Oakville, Ontario, CANADA
Is there a way of getting a list of all vRefNums? (Taking into account
that some volumes may have been mounted / dismounted since startup).
So, I looked in IM-Files, and found what I thought would work: GetVInfo,
but that didn't seem to help.
I looked in the FAQ, and was actually surprised not to see this there.
- --------------------
#### /\ #### Gilles Dignard - gdignard@hookup.net
#### ]\/\ /\/[ ####
#### \ \ / / #### Paradise is like where you are right
#### /--------\ #### now, only much, much better.
#### ][ #### -- Laurie Anderson
- --------------------
+++++++++++++++++++++++++++
>From skevill@tartarus.uwa.edu.au (Scott Kevill)
Date: 8 Apr 1995 03:58:14 GMT
Organization: The University of Western Australia
Gilles Dignard (gdignard@hookup.net) wrote:
: Is there a way of getting a list of all vRefNums? (Taking into account
: that some volumes may have been mounted / dismounted since startup).
: So, I looked in IM-Files, and found what I thought would work: GetVInfo,
: but that didn't seem to help.
: I looked in the FAQ, and was actually surprised not to see this there.
: ----------------------
: #### /\ #### Gilles Dignard - gdignard@hookup.net
: #### ]\/\ /\/[ ####
: #### \ \ / / #### Paradise is like where you are right
: #### /--------\ #### now, only much, much better.
: #### ][ #### -- Laurie Anderson
: ----------------------
You can't use GetVInfo to do this as it doesn't take a volume index
as a parameter. Use PBHGetVInfo like this:
HVolumeParam pb;
OSErr err;
short index;
pb.ioCompletion = NULL;
pb.ioNamePtr = NULL;
pb.ioVRefNum = 0;
err = noErr;
for (index=1; err != nsvErr; index ++) {
pb.ioVolIndex = index;
err = PBHGetVInfo(&pb, FALSE);
if (err == noErr) {
/* ... do what you want with pb.ioVRefNum ... */
}
}
Hope this helps.
Scott Kevill
skevill@tartarus.uwa.edu.au
+++++++++++++++++++++++++++
>From jumplong@aol.com (Jump Long)
Date: 8 Apr 1995 18:30:51 -0400
Organization: America Online, Inc. (1-800-827-6364)
>Is there a way of getting a list of all vRefNums? (Taking into account
>that some volumes may have been mounted / dismounted since startup).
>
>So, I looked in IM-Files, and found what I thought would work: GetVInfo,
>but that didn't seem to help.
>
>I looked in the FAQ, and was actually surprised not to see this there.
I think the FAQ refers you to MoreFiles for common File Manager related
routines.
In MoreFiles, you'll find a routine named OnLine that fills an array of
FSSpecs with an FSSpec for each mounted volume. You can use the code as
is and retrieve the vRefNums from the FSSpecs, or you can use it as an
example of how to index through the currently mounted volumes.
- Jim Luther
---------------------------
>From muffinhead@ins.infonet.net (MuffinHead)
Subject: __MAC__?
Date: 4 Apr 1995 11:32:54 GMT
Organization: Armpit Studios VII
I'm working on the Mac end of a cross-platform app. Is there a standard
#define in all Mac C compilers that lets the compiler know that the source
is being compiled on a Mac? For example, here's one line of our code:
#if (defined(__STDC__) && !defined(__HIGHC__) && !(defined(i386) &&
defined(MACH))) || (defined(sgi) && defined(__EXTENSIONS__))
and another:
#ifdef VAXC
What I need is something like:
#if defined(__MAC__)
I know that I could use defined(__MWERKS__) || defined(otherMacCompilers)
|| etc, but that seems a little kludgy. I couldn't find any such thing in
MacHeaders.
Muff Armpit Studios VII
Drummer, Mac geek Iowa City, IA
_____________________________________________________________________
Boy, giraffes are selfish.
--Deputy Barnard [P.|Milton|Oliver] Fife
+++++++++++++++++++++++++++
>From troika@panix.com (Mark Coniglio)
Date: 4 Apr 1995 13:20:57 GMT
Organization: Troika Ranch
In article <muffinhead-0404950632590001@s045.infonet.net>,
muffinhead@ins.infonet.net (MuffinHead) wrote:
> I'm working on the Mac end of a cross-platform app. Is there a standard
> #define in all Mac C compilers that lets the compiler know that the source
> is being compiled on a Mac? For example, here's one line of our code:
>
> #if (defined(__STDC__) && !defined(__HIGHC__) && !(defined(i386) &&
> defined(MACH))) || (defined(sgi) && defined(__EXTENSIONS__))
>
> and another:
>
> #ifdef VAXC
>
> What I need is something like:
>
> #if defined(__MAC__)
>
> I know that I could use defined(__MWERKS__) || defined(otherMacCompilers)
> || etc, but that seems a little kludgy. I couldn't find any such thing in
> MacHeaders.
>
If you are reading in the basic Mac headers,
you might just try checking for __QUICKDRAW__ as it is unlikely
that such a header definition would exist under Windows. ;-)
--
Mark Coniglio -- Troika Ranch / Dance Theater
mail: troika@panix.com
http: www.art.net/Studios/Performance/Dance/Troika_Ranch/TroikaHome.html
+++++++++++++++++++++++++++
>From woody@alumni.cco.caltech.edu (William Edward Woody)
Date: Tue, 04 Apr 1995 12:41:45 -0800
Organization: In Phase Consulting
muffinhead@ins.infonet.net (MuffinHead) wrote:
> What I need is something like:
>
> #if defined(__MAC__)
>
> I know that I could use defined(__MWERKS__) || defined(otherMacCompilers)
> || etc, but that seems a little kludgy. I couldn't find any such thing in
> MacHeaders.
What I did was to modify the MacHeaders to add the statement
#define __MACINTOSH__ 1
and then precompile MacHeaders.
On the Windows software I write, I predefine (using Borland's or Microsoft's
ability to predefine a symbol from the command line) the symbol
#define __WINDOWS__ 1
for the same functionality under Windows.
Works for me, though it means handing someone else the source kit is a
little problamatical... :-(
- Bill
--
William Edward Woody | e-mail: woody@alumni.cco.caltech.edu
In Phase Consulting | WWW: http://alumni.caltech.edu/~woody
337 West California #4 | Fax: (818) 502-1467
Glendale, CA 91203 | ICBM: N:34.4' W:118.15'
+++++++++++++++++++++++++++
>From muffinhead@ins.infonet.net (MuffinHead)
Date: 5 Apr 1995 08:51:33 GMT
Organization: Armpit Studios VII
Thanks for the tips. I think I'll go with the QuickDraw define since
this code is public domain.
Muff Armpit Studios VII
Drummer, Mac geek Iowa City, IA
_____________________________________________________________________
Boy, giraffes are selfish.
--Deputy Barnard [P.|Milton|Oliver] Fife
+++++++++++++++++++++++++++
>From mattm@apple.com (Matthew Melmon)
Date: Mon, 10 Apr 1995 06:52:25 GMT
Organization: Apple Computer, Inc.
> In article <muffinhead-0404950632590001@s045.infonet.net>,
> muffinhead@ins.infonet.net (MuffinHead) wrote:
>
> > I'm working on the Mac end of a cross-platform app. Is there a standard
> > #define in all Mac C compilers that lets the compiler know that the source
> > is being compiled on a Mac? For example, here's one line of our code:
The following conditional macros exist for determining platform:
GENERATINGPOWERPC
GENERATING68K
GENERATINGCFM
They are particularly useful when tweaking an app which spans
the PowerPC and 68K platform. GENERATINGCFM is defined for both
PowerPC and the new CFM 68K runtime. You may also use __CFM68K__
for the latter (when, for example, you want to turn on exports
on and off in a header file).
--
*X*
Splatasha, Queen of the Damned (Vanishing Sig)
---------------------------
End of C.S.M.P. Digest
**********************